package com.xinwei.leetcode.数组;

import java.util.Arrays;

// https://leetcode-cn.com/problems/binary-search/

// 数组编码尽量选择左闭右开
public class _704_二分查找 {
    public int search(int[] nums, int target) {
        int begin = 0;
        int end = nums.length;
        int mid;
        while (begin != end) {
            mid = (begin + end) >> 2;
            if (target > nums[mid]) {
                begin = mid + 1;
            }else if (target < nums[mid]) {
                end = mid;
            }else {
                return mid;
            }
        }
        return 0;
    }
}
